export const sum = (arr) => {
  const sums = [];
  const action = {
    C: () => sums.pop(),
    D: () => sums.push((sums[sums.length -1] || 0) * 2),
    "+": () => sums.push((sums[sums.length - 1] || 0) + (sums[sums.length -2] || 0))
  }

  for (let i of arr) {
    action[i] ? action[i]() : sums.push(Number.isNaN(Number(i)) ? 0 : Number(i))
  }

  return sums.reduce((pre, cur) => pre + cur)
}